// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoCommon.Music { using Abstract; using JetBrains.Annotations; using Localization; using System; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; /// /// Abstract Change. /// public class AbstractChange { #region Constructors /// /// Initializes a new instance of the class. /// /// The given change. public AbstractChange(XElement xchange) { Contract.Requires(xchange != null); if (xchange == null) { return; } this.BarNumber = XmlSupport.ReadIntegerAttribute(xchange.Attribute("Bar")); this.LineIndex = XmlSupport.ReadByteAttribute(xchange.Attribute("Line")); var changeTypeStr = XmlSupport.ReadStringAttribute(xchange.Attribute("Type")); this.ChangeType = string.IsNullOrEmpty(changeTypeStr) ? MusicalChangeType.None : (MusicalChangeType)Enum.Parse(typeof(MusicalChangeType), changeTypeStr); //// this.ChangeType = (MusicalChangeType)LibSupport.ReadIntegerAttribute(xchange.Attribute("ChangeType")); this.IsStop = XmlSupport.ReadBooleanAttribute(xchange.Attribute("IsStop")); } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. /// Type of the given. protected AbstractChange(int givenBar, int givenLineIndex, MusicalChangeType givenType) { this.BarNumber = givenBar; this.LineIndex = givenLineIndex; this.ChangeType = givenType; this.IsStop = false; } /// /// Initializes a new instance of the class. /// protected AbstractChange() { } #endregion #region Properties - Xml /// Gets Xml representation. /// Property description. public virtual XElement GetXElement { get { //// Contract.Requires(this.BitRange != null); var xmlBitRange = new XElement( "Change", new XAttribute("Type", this.ChangeType), new XAttribute("Bar", this.BarNumber), new XAttribute("Line", this.LineIndex)); return xmlBitRange; } } #endregion #region Properties /// /// Gets or sets the type of the change. /// /// /// The type of the change. /// public MusicalChangeType ChangeType { get; protected set; } /// Gets class of melodic part. /// Property description. public int BarNumber { get; } /// Gets line index i.e. mark of the line in the musical model. /// Property description. public int LineIndex { get; } /// /// Gets a value indicating whether this instance is empty. /// /// /// Is true if this instance is empty; otherwise, false. /// [System.Diagnostics.Contracts.Pure, UsedImplicitly] public bool IsMotivic => this.MusicalLineType == MusicalLineType.Melodic || this.MusicalLineType == MusicalLineType.Rhythmic || this.MusicalLineType == MusicalLineType.Harmonic; /// /// Gets or sets the type of the musical line. /// /// /// The type of the musical line. /// public MusicalLineType MusicalLineType { get; set; } /// Gets a value indicating whether Part classification according to current status. /// General musical property. [System.Diagnostics.Contracts.Pure] public bool IsMelodicalNature => this.MusicalLineType == MusicalLineType.Melodic; /// /// Gets or sets a value indicating whether this instance is stop. /// /// /// Is true if this instance is stop; otherwise, false. /// public bool IsStop { [UsedImplicitly] get; set; } /// /// Gets LineTypeString. /// /// Property description. [System.Diagnostics.Contracts.Pure] [UsedImplicitly] public string LineTypeString => LocalizedMusic.String("LineType" + ((byte)this.MusicalLineType).ToString(CultureInfo.CurrentCulture)); #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. [System.Diagnostics.Contracts.Pure] public virtual object Clone() { var tmc = new AbstractChange(this.BarNumber, this.LineIndex, this.ChangeType); //// tmc.BlockModel = this.BlockModel; return tmc; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.Append(string.Format(CultureInfo.CurrentCulture, "Bar number {0},", this.BarNumber)); s.Append(string.Format(CultureInfo.CurrentCulture, "Line index {0},", this.LineIndex)); s.Append("Type " + this.ChangeType); return s.ToString(); } #endregion } }